package com.hongning.railway.ui.main.mine.score;

import android.app.Application;
import android.databinding.ObservableArrayList;
import android.databinding.ObservableList;
import android.support.annotation.NonNull;

import com.hongning.railway.BR;
import com.hongning.railway.R;
import com.hongning.railway.data.AppRepository;
import com.hongning.railway.entity.reqbean.ReqScoreBean;
import com.hongning.railway.entity.resbean.ResDetailScore;
import com.hongning.railway.entity.resbean.ResListScoreDetailBean;
import com.hongning.railway.ui.main.mine.score.itemviewmodel.SocreDetailItemViewModel;
import com.hongning.railway.util.Apputils;

import java.util.List;

import me.goldze.mvvmhabit.base.BaseViewModel;
import me.goldze.mvvmhabit.http.ApiDisposableObserver;
import me.goldze.mvvmhabit.utils.RxUtils;
import me.tatarka.bindingcollectionadapter2.ItemBinding;

public class SocreDetailFragmentViewModel extends BaseViewModel<AppRepository> {

    public ItemBinding<SocreDetailItemViewModel> item = ItemBinding.of(BR.viewModel,R.layout.item_score_detail);
    public ObservableList<SocreDetailItemViewModel> viewlist = new ObservableArrayList<>();
    public SocreDetailFragmentViewModel(@NonNull Application application) {
        super(application);
    }

    public SocreDetailFragmentViewModel(@NonNull Application application, AppRepository model) {
        super(application, model);
    }

    public void loadListData(){
        ReqScoreBean reqScoreBean = new ReqScoreBean();
        reqScoreBean.setStaffId(Apputils.getStaffid());
        model.ScoreDetail(reqScoreBean)
                .compose(RxUtils.schedulersTransformer())
                .compose(RxUtils.bindToLifecycle(getLifecycleProvider()))
                .subscribe(new ApiDisposableObserver<ResDetailScore>() {
                    @Override
                    public void onResult(ResDetailScore resDetailScore) {
                        for (ResListScoreDetailBean data:resDetailScore.getDetialScore()) {
                            viewlist.add(new SocreDetailItemViewModel(SocreDetailFragmentViewModel.this,data));
                        }
                    }
                });
    }
}
